package com.agileboot.api.controller.app;

import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.domain.app.application.LoanApplicationService;
import com.agileboot.domain.app.application.command.AppLoanApplicationDTO;
import com.agileboot.domain.app.product.ProductService;
import com.agileboot.domain.app.product.command.AppProductDTO;
import com.agileboot.domain.app.product.db.AppLoanProductEntity;
import com.agileboot.domain.app.product.utils.LoanCalculator;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/app")
@AllArgsConstructor
public class ProductController {

    private final ProductService productService;

    @RequestMapping("/product/info")
    public Object product(@RequestBody AppProductDTO command) {
        AppLoanProductEntity productInfo = productService.findProductInfo(command);

        return ResponseDTO.ok(productInfo);
    }


    private final LoanCalculator calculator;

    /**
     * 计算还款计划
     *
     * @return 还款计划
     */
    @PostMapping("/repayment/schedule")
    public ResponseDTO<?> repayment() {
        calculator.setName("张三");
        calculator.setAge(35);
        calculator.setMonthlyIncome(50000);
        calculator.setOccupation("工程师");
        calculator.setCreditScore(750);
        calculator.setTotalLiabilities(100);

        calculator.setLoanType("个人贷款");
        calculator.setLoanTerm(36);
        calculator.setInterestRate(0.17);
        calculator.setRepaymentMethod("等额本息");

        List<String> strings = calculator.generateRepaymentSchedule(3000, calculator.getLoanTerm());
        // 我想做一个个人信贷系统，现在需要一个工具类,目前我设计了三个版块，分别是：个人基础信息、个人房产信息、个人汽车信息，这三个模块是独立存在的，我期望的用户每填写一个模块，就自动生成一个贷款申请单，并且这个贷款申请单可以保存到数据库中，然后用户可以查看自己所有的贷款申请，管理员如果审核通过了这笔贷款申请，那么就给用户账号加贷款额度，并且用户可以查看自己的账户余额。请帮我实现这个工具类。
        return ResponseDTO.ok();
    }


    private final LoanApplicationService loanApplicationService;

    /**
     * 申请贷款
     *
     * @param bean 申请贷款
     */
    @PostMapping("/loan/application")
    public ResponseDTO<?> carApply(@RequestBody AppLoanApplicationDTO bean) {
        loanApplicationService.addLoanApplication(bean);
        return ResponseDTO.ok();
    }

}
